package kitrobot.com.bed.Service;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import kitrobot.com.bed.StreamTools;

public class IdentifyingService {
    public static String IdentifyingByClientPost(String phone){
    try{
        HttpClient client=new DefaultHttpClient();
        String path="http://47.106.217.3:8360/app/user/code";
        HttpPost httpPost=new HttpPost(path);
        List<NameValuePair>parmeters=new ArrayList<NameValuePair>();
        parmeters.add(new BasicNameValuePair("phone",phone));
        httpPost.setEntity(new UrlEncodedFormEntity(parmeters,"UTF-8"));
        HttpResponse response=client.execute(httpPost);
        int code=response.getStatusLine().getStatusCode();
        if(code==200){
            InputStream is=response.getEntity().getContent();
            String text= StreamTools.readInputStream(is);
            return text;
        }
        else{
            return null;
        }
    }catch (Exception e){
        e.printStackTrace();
        return null;
    }
    }
}
